<template>
  <div id="echarts3"></div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  props: ['data'],
  data() {
    return {}
  },
  mounted() {
    this.initEcharts()
  },
  methods: {
    initEcharts(data, labels) {
      data = [35, 9, 11, 14, 7]
      labels =["非常满意", "满意", "一般", "不满意", "非常不满意"]
      const newData  = data.map((item,index)=>({value:item,name:`${labels[index]}(${item})`}))
      const chartDom = document.getElementById('echarts3')
      const myChart = echarts.init(chartDom)
      let option

      option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          right: '10',
          orient:'vertical',
          bottom: '10'
        },
        grid:{
          y:0
        },
        series: [
          {
            name: '',
            type: 'pie',
            radius: '65%',
            data: newData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }
  },
  watch: {
    data({data, labels}) {
      this.initEcharts(data, labels)
    }
  }
}
</script>

<style scoped>
#echarts3 {
  width: 100%;
  height: 500px;
}
</style>
